package com.ijtunes.filetypes;

/**
 * File implementation of a track.
 * @author Michael Sena
 * @version 1.0
 * @date 01/07/2010
 */
public class File extends Track {
    // TODO: Add support for files

    /**
     * Default constructor.
     * @param fileLocation Location of the file
     */
    public File(final String fileLocation) {
        location = fileLocation;
        name = getMP3File().getID3v1Tag().getTitle();
        artist = getMP3File().getID3v1Tag().getArtist();
        exists = (getFile().exists());
        // TODO: Supported file-types detection for Files
        supported = true;
    }

    /**
     * Sets the genre of the track.
     * @param trackGenre Genre name to store
     */
    @Override
    public final void setGenre(final String trackGenre) {
        getMP3File().getID3v2Tag().setSongGenre(trackGenre);
    }

    /**
     * Genre of the track.
     * @return String version of the genre.
     */
    @Override
    public final String getGenre() {
        if (genre == null) {
            genre = getMP3File().getID3v1Tag().getSongGenre();
        }
        return genre;
    }

    /**
     * Album the track appears on.
     * @return String version of the album name.
     */
    @Override
    public final String getAlbum() {
        if (album == null) {
            try {
                album = getMP3File().getID3v1Tag().getAlbum();
            } catch (NullPointerException npe) {
                album = "";
            }
        }

        return album;
    }

    /**
     * Artist of the whole album (different).
     * @return String version of the album artist
     */
    @Override
    public final String getAlbumArtist() {
        // TODO: Implement correct album artists for files
        if (albumArtist == null) {
            albumArtist = getMP3File().getID3v1Tag().getLeadArtist();
        }
        return albumArtist;
    }

    /**
     * Track number on the album.
     * @return Integer version of the track number.
     */
    @Override
    public final int getTrackNum() {
        if (trackNum == -1) {
            trackNum = Integer.parseInt(
                getMP3File().getID3v2Tag().getTrackNumberOnAlbum());
        }
        return trackNum;
    }
}
